package com.xnyzc.lhy.mis.config;

import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.CertAlipayRequest;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.internal.util.AlipaySignature;
import com.alipay.api.request.*;
import com.alipay.api.response.*;
import com.xnyzc.lhy.common.util.IDUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Configuration;
import java.math.BigDecimal;

/**
 * 支付宝配置和实现方法
 */
@Slf4j
@Configuration
@EnableCaching
public class AlipayConfig {

    /** 支付宝应用id：入参app_id */
    public static final String APPID = "2021002125620071";
    /** 私钥 */
    public static final String RSA_PRIVATE = "MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQCY/Mqjae0yYl7brw/1a0v1KDXgX88fwjgvPMzpZtnsGcdOzhN8sxUO1xOZt/5elFZiyvlBiGXc47l2gByJNqW45ICh7Q60PsO3SB+xQMflgaUS678S7XG1qMt5AB4CvCB76pbd5K/lZJVxRUuzfsUXFPmm+EOILKkhPW91P1f45RSFXC+uhEjoEjYg/dZF6eKxKeBgzDNj9y8tUbhQOQc7uRB5tFpsg0i0ZfaT6vh0Db6jJZIFdaMV04g/Hi0JRf3cGZyHPQ/2CX1A0pSJfVoQfaQu6dM3PY9x9IOKXnTOYKF2H8JmMGdEnaQ56IC75jQSNy6R29XLgKN+IIjZp7idAgMBAAECggEBAJdqm6ThUkJr2jbULZdZevRJuAk6ymVEdRdLtgPMKCPl372/eMoS9OSbOmsKEFjLuDRPcCPMPAVD3mvKoHOuApfckPOzDLqY5Fyipbtpwm8EwbzYV2UEXWbOiZRY6VsLl5sNtAQqM212//H8A9DDx43w1KbNUQmWKk8b3xTMfOV5R8cuNenVjJdDtfP2O3Lo8w/CFSI42HQYU/Hn1lOytsEe9QVu66r933hMoDotrG0x8qc8Y6niJ6eYgd4xXeSb+YG2prgJ7eJMkIeF7dgG3nGeNJC/wuxQY5XplCQyRKPDRo19juF3EA4AVlBsAFz3trt1/Z16z6WOshv3copt3oECgYEA7FlETikSILC/pWFmuGjdxlg/XsdU6jz84uOJh074921GZ5YYOWxj3MTQHk40KmLvY8lKNXfW8AiQkXp2SN2+9prn17JSer4kvZYeDjv5dSZeGUJZC4oB0fybW29WpQbnikYTkO9Tdo17aaAdPIb0ZjqNSuUAL5IL4ezegXhj/GcCgYEApbUpszPQaTUcdYBlCwJpzE4Y9qhwnPYJCvQLWQ7au1zzA62KQPomM0SpEjcCTaUkiz+3tA0HVCpvYecvS4TXnKu5QAmkVugY1ZAYNp5jeVdBXYZwXu4y9oTUoi2yZr23kN6yib+V5LKFu3tZB4zAN/saMWVnqJ9h+JcHn47bAFsCgYEAjvzejy7X0cE84LARtiVzbsj65btQizoEgLvJ+3tysjaBLrAmza7ep7TGeF81viMG02b3J2vuNF/qHqlpIGJPYuCKvPscXTfmAHDulAwCurZQnZV/S7Tdrw3Va7brQ4Hu2L/WnIu+Ae5MqLV+mpzHBYYM7y+mMiF4YOGuJ8QPMacCgYAKP3LtvzWTXBJ/fcpB7QtH9Eh88JvOSTTz9XXCMzX5wlzRDGlxbUbxgryGANrmnGDvL6iXvPqIDPvIbTiyjeubp88UE8STD1WB16B3uEHkni3Pr+HBLS//qOVRhkvzKKZykiMue6e0dgnpN06hNeYpUCEljuTjO8AeVJDHIFmQ4wKBgQCbygVkG2d9LnxixDI2DtMpFEU//ywH/BZLxL7Obz4Of5Wd7ORWSnNNslB5193jliujSQbFS84tsECgvAJDKYihEGrC5WUCxWgX2ladIxZGMawOQEGrBrZ9AxXaU/NhvqbkPOnAyUTBaEkwxnMqgfT79e9eCYhh47XvHv+fLSUHZw==";
    /** 默认网关 */
    public static final String PAY_DEFAULT_URL = "https://openapi.alipay.com/gateway.do";
    /** 支付宝公钥，由支付宝生成 */
    public static final String ALIPAY_PUBLIC_KEY = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnx+Vyi3Baeuehk/qjjC6/DLObyenuKxglrUfWpaxZqgm6fxUDQv3CvLgxLsQqVAwbq/SWbz8aR3F1eG/s44KwQ7RcJiLDg5GsxASSwMG+QlVAqZHuazazyxZW4DpFlsf4yfLGDFXOCqjYMN6nLl31zeNAJbtcZI+t4wa9YaJ7batn6dtgbN3q0+JtnZTVIqFifi6g16dhL6QEMz66ZjHQwwUF8BLY0l9EYscvB2pQEQynI0DkqWs9p8fUOaFoiZb9IC7PgBSj+qGGa3z2DvDnOzCm0UlH7ZlicD3+9hBZcd14ElZpPBDm+HLVIFoz51ErZSt9suQ6K75ywqg38wJBQIDAQAB";
//    @Value("appCertPublicKeyPath.config")
//    public static String appCertPublicKeyPath;
//    @Value("alipayCertPublicKey_RSA2Path.config")
//    public static String alipayCertPublicKey_RSA2Path;
//    @Value("alipayRootCertPath.config")
//    public static String alipayRootCertPath;
//    /**
//     * 单笔转账 具体实现的方法 (证书方式)
//     * @param orderNo 商家订单号
//     * @param amount    金额
//     * @param payeeIdentity 参与方的唯一标识
//     * @param payeeName   参与方真实姓名
//     * @return
//     */
//    public static String getSingleTransfer(String orderNo, BigDecimal amount,String payeeIdentity,String payeeName)  {
//        //调用后返回信息体
//        StringBuffer body = new StringBuffer();
//
//        //构造client
//        CertAlipayRequest certAlipayRequest = new CertAlipayRequest();
//        //设置网关地址
//        certAlipayRequest.setServerUrl(PAY_DEFAULT_URL);
//        //设置应用Id
//        certAlipayRequest.setAppId(APPID);
//        //设置应用私钥
//        certAlipayRequest.setPrivateKey(RSA_PRIVATE);
//        //设置请求格式，固定值json
//        certAlipayRequest.setFormat("json");
//        //设置字符集
//        certAlipayRequest.setCharset("UTF-8");
//        //设置签名类型
//        certAlipayRequest.setSignType("RSA2");
//        //设置应用公钥证书路径和内容
//        //certAlipayRequest.setCertPath("C:\\Users\\Administrator\\Desktop\\appCertPublicKey.crt");
//        certAlipayRequest.setCertContent("-----BEGIN CERTIFICATE-----\n" +
//                "MIIEsTCCA5mgAwIBAgIQICEBGa9Y1gFgqeiwsjIYiDANBgkqhkiG9w0BAQsFADCBgjELMAkGA1UE\n" +
//                "BhMCQ04xFjAUBgNVBAoMDUFudCBGaW5hbmNpYWwxIDAeBgNVBAsMF0NlcnRpZmljYXRpb24gQXV0\n" +
//                "aG9yaXR5MTkwNwYDVQQDDDBBbnQgRmluYW5jaWFsIENlcnRpZmljYXRpb24gQXV0aG9yaXR5IENs\n" +
//                "YXNzIDEgUjEwHhcNMjEwMTE5MTA1MjM5WhcNMjMwMTE5MTA1MjM5WjB5MQswCQYDVQQGEwJDTjEt\n" +
//                "MCsGA1UECgwk5oiQ6YO96J6N5pm65rG96L2m5pyN5Yqh5pyJ6ZmQ5YWs5Y+4MQ8wDQYDVQQLDAZB\n" +
//                "bGlwYXkxKjAoBgNVBAMMITIwODg5MDE0OTcyNTM3MjEtMjAyMTAwMjEyNTYyMDA3MTCCASIwDQYJ\n" +
//                "KoZIhvcNAQEBBQADggEPADCCAQoCggEBAO9Hv0X4lmnndKwRIL4iGg64PWEEBQY1crW5jagLwqxA\n" +
//                "onjUgsquR4iu4kok6kkGwnMCMAK06VHyRsj5DMmV9fRrweoLbC0cUK+xqyjv9275SXLuh7pIBlk1\n" +
//                "XohX9MGGfJtRQkO+i3fAtCRoRIVeexoyvEgQh5v8z+KV+BX6P2yyzF7+6PxQhz+IZV/OE5XUQ4p9\n" +
//                "nc6oy/Fu/QAiwLFI5WRa2rUHniHKPgHlXMef3gKh60dEpIySv7WS699oYvl9KGt6EnWLatvQO+nf\n" +
//                "BH82q5HP2zLpRVvh7ZLlB/t+67zHuRmS0Enf4YIGyLrTg5psj1g6zq/03qD6CxT1q1OGhd8CAwEA\n" +
//                "AaOCASkwggElMB8GA1UdIwQYMBaAFHEH4gRhFuTl8mXrMQ/J4PQ8mtWRMB0GA1UdDgQWBBQrKq4d\n" +
//                "zlT5seLGygyRb+MyqukSCjBABgNVHSAEOTA3MDUGB2CBHAFuAQEwKjAoBggrBgEFBQcCARYcaHR0\n" +
//                "cDovL2NhLmFsaXBheS5jb20vY3BzLnBkZjAOBgNVHQ8BAf8EBAMCBsAwLwYDVR0fBCgwJjAkoCKg\n" +
//                "IIYeaHR0cDovL2NhLmFsaXBheS5jb20vY3JsNDkuY3JsMGAGCCsGAQUFBwEBBFQwUjAoBggrBgEF\n" +
//                "BQcwAoYcaHR0cDovL2NhLmFsaXBheS5jb20vY2E2LmNlcjAmBggrBgEFBQcwAYYaaHR0cDovL2Nh\n" +
//                "LmFsaXBheS5jb206ODM0MC8wDQYJKoZIhvcNAQELBQADggEBAFi2/FO4PSRuouzbyRg0TyiwGy79\n" +
//                "O+LgT4vMnZa+pJqkgA/Xlixu+hlcJnKwp/THV6OzOBdTkNa1dQhaG2ZDNy9rcVna0/9ehW50zg6O\n" +
//                "ODpE/i0jp4fbUg0ezpnxONLPPizEfxxjoV7CfPKel7YxRuhU8+KE56HP9bS1oQty/cyv32oBWhS+\n" +
//                "AuxeEjzOBo9bedchomhEMiquCE1KfDFrN9FQi5W229FimAPa3dDcicz6ppxSNvdVSmsVcg4H+VjG\n" +
//                "VO1IUzqpMWSiJpI5OzWal2LAAWH/uJBA1QWIKBxMnohcd+vLpyZA5Qliz2d1UCWJW1nskL1PnCc4\n" +
//                "Zvpu6N4pA1M=\n" +
//                "-----END CERTIFICATE-----");
//        //设置支付宝公钥证书路径和内容
//        //certAlipayRequest.setAlipayPublicCertPath("C:\\Users\\Administrator\\Desktop\\alipayCertPublicKey_RSA2.crt");
//        certAlipayRequest.setAlipayPublicCertContent("-----BEGIN CERTIFICATE-----\n" +
//                "MIIDsjCCApqgAwIBAgIQIBkIIZxAbJS+jH/Wvo1ZADANBgkqhkiG9w0BAQsFADCBgjELMAkGA1UE\n" +
//                "BhMCQ04xFjAUBgNVBAoMDUFudCBGaW5hbmNpYWwxIDAeBgNVBAsMF0NlcnRpZmljYXRpb24gQXV0\n" +
//                "aG9yaXR5MTkwNwYDVQQDDDBBbnQgRmluYW5jaWFsIENlcnRpZmljYXRpb24gQXV0aG9yaXR5IENs\n" +
//                "YXNzIDIgUjEwHhcNMTkwODIxMDMwMjAxWhcNMjEwODIwMDMwMjAxWjCBkjELMAkGA1UEBhMCQ04x\n" +
//                "LTArBgNVBAoMJOaIkOmDveiejeaZuuaxvei9puacjeWKoeaciemZkOWFrOWPuDEPMA0GA1UECwwG\n" +
//                "QWxpcGF5MUMwQQYDVQQDDDrmlK/ku5jlrp0o5Lit5Zu9Kee9kee7nOaKgOacr+aciemZkOWFrOWP\n" +
//                "uC0yMDg4OTAxNDk3MjUzNzIxMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnx+Vyi3B\n" +
//                "aeuehk/qjjC6/DLObyenuKxglrUfWpaxZqgm6fxUDQv3CvLgxLsQqVAwbq/SWbz8aR3F1eG/s44K\n" +
//                "wQ7RcJiLDg5GsxASSwMG+QlVAqZHuazazyxZW4DpFlsf4yfLGDFXOCqjYMN6nLl31zeNAJbtcZI+\n" +
//                "t4wa9YaJ7batn6dtgbN3q0+JtnZTVIqFifi6g16dhL6QEMz66ZjHQwwUF8BLY0l9EYscvB2pQEQy\n" +
//                "nI0DkqWs9p8fUOaFoiZb9IC7PgBSj+qGGa3z2DvDnOzCm0UlH7ZlicD3+9hBZcd14ElZpPBDm+HL\n" +
//                "VIFoz51ErZSt9suQ6K75ywqg38wJBQIDAQABoxIwEDAOBgNVHQ8BAf8EBAMCA/gwDQYJKoZIhvcN\n" +
//                "AQELBQADggEBAEahhgaxaDYrerchcsXJtY+zZEOSSZdF0qSOesLGSZQNK4hNrYHHGo4c0UE8Prqr\n" +
//                "P/2mM0JRcCssDdGuIFnTNaCK4XDi15FWLlQszURZYNvxZBSUu9OJ/2YeHTkombf5urKsPeKhrnt0\n" +
//                "fNeg1cPatgt9n96qzT0gpVeZ1D932ON19EJ6mHrzVPZQ5m+P1XAoY97lm+l42dLR3JA/+5GYMfzl\n" +
//                "pT7tUf6s9kNNke3BjI+QYNYAYvdNQ02DZue3wzMWZmXq/b1KsoTh8+iQWCvxn4zAM4U1J0Vlob44\n" +
//                "0m1NaAjNx8T4V6GagLpnrm2NEuehRkYe0b7j6y66ilbjq/r07W8=\n" +
//                "-----END CERTIFICATE-----\n" +
//                "-----BEGIN CERTIFICATE-----\n" +
//                "MIIE4jCCAsqgAwIBAgIIYsSr5bKAMl8wDQYJKoZIhvcNAQELBQAwejELMAkGA1UEBhMCQ04xFjAUBgNVBAoMDUFudCBGaW5hbmNpYWwxIDAeBgNVBAsMF0NlcnRpZmljYXRpb24gQXV0aG9yaXR5MTEwLwYDVQQDDChBbnQgRmluYW5jaWFsIENlcnRpZmljYXRpb24gQXV0aG9yaXR5IFIxMB4XDTE4MDMyMjE0MzQxNVoXDTM3MTEyNjE0MzQxNVowgYIxCzAJBgNVBAYTAkNOMRYwFAYDVQQKDA1BbnQgRmluYW5jaWFsMSAwHgYDVQQLDBdDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTE5MDcGA1UEAwwwQW50IEZpbmFuY2lhbCBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eSBDbGFzcyAyIFIxMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsLMfYaoRoPRbmDcAfXPCmKf43pWRN5yTXa/KJWO0l+mrgQvs89bANEvbDUxlkGwycwtwi5DgBuBgVhLliXu+R9CYgr2dXs8D8Hx/gsggDcyGPLmVrDOnL+dyeauheARZfA3du60fwEwwbGcVIpIxPa/4n3IS/ElxQa6DNgqxh8J9Xwh7qMGl0JK9+bALuxf7B541Gr4p0WENG8fhgjBV4w4ut9eQLOoa1eddOUSZcy46Z7allwowwgt7b5VFfx/P1iKJ3LzBMgkCK7GZ2kiLrL7RiqV+h482J7hkJD+ardoc6LnrHO/hIZymDxok+VH9fVeUdQa29IZKrIDVj65THQIDAQABo2MwYTAfBgNVHSMEGDAWgBRfdLQEwE8HWurlsdsio4dBspzhATAdBgNVHQ4EFgQUSqHkYINtUSAtDPnS8XoyoP9p7qEwDwYDVR0TAQH/BAUwAwEB/zAOBgNVHQ8BAf8EBAMCAQYwDQYJKoZIhvcNAQELBQADggIBAIQ8TzFy4bVIVb8+WhHKCkKNPcJe2EZuIcqvRoi727lZTJOfYy/JzLtckyZYfEI8J0lasZ29wkTta1IjSo+a6XdhudU4ONVBrL70U8Kzntplw/6TBNbLFpp7taRALjUgbCOk4EoBMbeCL0GiYYsTS0mw7xdySzmGQku4GTyqutIGPQwKxSj9iSFw1FCZqr4VP4tyXzMUgc52SzagA6i7AyLedd3tbS6lnR5BL+W9Kx9hwT8L7WANAxQzv/jGldeuSLN8bsTxlOYlsdjmIGu/C9OWblPYGpjQQIRyvs4Cc/mNhrh+14EQgwuemIIFDLOgcD+iISoN8CqegelNcJndFw1PDN6LkVoiHz9p7jzsge8RKay/QW6C03KNDpWZEUCgCUdfHfo8xKeR+LL1cfn24HKJmZt8L/aeRZwZ1jwePXFRVtiXELvgJuM/tJDIFj2KD337iV64fWcKQ/ydDVGqfDZAdcU4hQdsrPWENwPTQPfVPq2NNLMyIH9+WKx9Ed6/WzeZmIy5ZWpX1TtTolo6OJXQFeItMAjHxW/ZSZTok5IS3FuRhExturaInnzjYpx50a6kS34c5+c8hYq7sAtZ/CNLZmBnBCFDaMQqT8xFZJ5uolUaSeXxg7JFY1QsYp5RKvj4SjFwCGKJ2+hPPe9UyyltxOidNtxjaknOCeBHytOr\n" +
//                "-----END CERTIFICATE-----\n");
//        //设置支付宝根证书路径和内容
//        //certAlipayRequest.setRootCertPath("C:\\Users\\Administrator\\Desktop\\alipayRootCert.crt");
//        certAlipayRequest.setRootCertContent("-----BEGIN CERTIFICATE-----\n" +
//                "MIIBszCCAVegAwIBAgIIaeL+wBcKxnswDAYIKoEcz1UBg3UFADAuMQswCQYDVQQG\n" +
//                "EwJDTjEOMAwGA1UECgwFTlJDQUMxDzANBgNVBAMMBlJPT1RDQTAeFw0xMjA3MTQw\n" +
//                "MzExNTlaFw00MjA3MDcwMzExNTlaMC4xCzAJBgNVBAYTAkNOMQ4wDAYDVQQKDAVO\n" +
//                "UkNBQzEPMA0GA1UEAwwGUk9PVENBMFkwEwYHKoZIzj0CAQYIKoEcz1UBgi0DQgAE\n" +
//                "MPCca6pmgcchsTf2UnBeL9rtp4nw+itk1Kzrmbnqo05lUwkwlWK+4OIrtFdAqnRT\n" +
//                "V7Q9v1htkv42TsIutzd126NdMFswHwYDVR0jBBgwFoAUTDKxl9kzG8SmBcHG5Yti\n" +
//                "W/CXdlgwDAYDVR0TBAUwAwEB/zALBgNVHQ8EBAMCAQYwHQYDVR0OBBYEFEwysZfZ\n" +
//                "MxvEpgXBxuWLYlvwl3ZYMAwGCCqBHM9VAYN1BQADSAAwRQIgG1bSLeOXp3oB8H7b\n" +
//                "53W+CKOPl2PknmWEq/lMhtn25HkCIQDaHDgWxWFtnCrBjH16/W3Ezn7/U/Vjo5xI\n" +
//                "pDoiVhsLwg==\n" +
//                "-----END CERTIFICATE-----\n" +
//                "\n" +
//                "-----BEGIN CERTIFICATE-----\n" +
//                "MIIF0zCCA7ugAwIBAgIIH8+hjWpIDREwDQYJKoZIhvcNAQELBQAwejELMAkGA1UE\n" +
//                "BhMCQ04xFjAUBgNVBAoMDUFudCBGaW5hbmNpYWwxIDAeBgNVBAsMF0NlcnRpZmlj\n" +
//                "YXRpb24gQXV0aG9yaXR5MTEwLwYDVQQDDChBbnQgRmluYW5jaWFsIENlcnRpZmlj\n" +
//                "YXRpb24gQXV0aG9yaXR5IFIxMB4XDTE4MDMyMTEzNDg0MFoXDTM4MDIyODEzNDg0\n" +
//                "MFowejELMAkGA1UEBhMCQ04xFjAUBgNVBAoMDUFudCBGaW5hbmNpYWwxIDAeBgNV\n" +
//                "BAsMF0NlcnRpZmljYXRpb24gQXV0aG9yaXR5MTEwLwYDVQQDDChBbnQgRmluYW5j\n" +
//                "aWFsIENlcnRpZmljYXRpb24gQXV0aG9yaXR5IFIxMIICIjANBgkqhkiG9w0BAQEF\n" +
//                "AAOCAg8AMIICCgKCAgEAtytTRcBNuur5h8xuxnlKJetT65cHGemGi8oD+beHFPTk\n" +
//                "rUTlFt9Xn7fAVGo6QSsPb9uGLpUFGEdGmbsQ2q9cV4P89qkH04VzIPwT7AywJdt2\n" +
//                "xAvMs+MgHFJzOYfL1QkdOOVO7NwKxH8IvlQgFabWomWk2Ei9WfUyxFjVO1LVh0Bp\n" +
//                "dRBeWLMkdudx0tl3+21t1apnReFNQ5nfX29xeSxIhesaMHDZFViO/DXDNW2BcTs6\n" +
//                "vSWKyJ4YIIIzStumD8K1xMsoaZBMDxg4itjWFaKRgNuPiIn4kjDY3kC66Sl/6yTl\n" +
//                "YUz8AybbEsICZzssdZh7jcNb1VRfk79lgAprm/Ktl+mgrU1gaMGP1OE25JCbqli1\n" +
//                "Pbw/BpPynyP9+XulE+2mxFwTYhKAwpDIDKuYsFUXuo8t261pCovI1CXFzAQM2w7H\n" +
//                "DtA2nOXSW6q0jGDJ5+WauH+K8ZSvA6x4sFo4u0KNCx0ROTBpLif6GTngqo3sj+98\n" +
//                "SZiMNLFMQoQkjkdN5Q5g9N6CFZPVZ6QpO0JcIc7S1le/g9z5iBKnifrKxy0TQjtG\n" +
//                "PsDwc8ubPnRm/F82RReCoyNyx63indpgFfhN7+KxUIQ9cOwwTvemmor0A+ZQamRe\n" +
//                "9LMuiEfEaWUDK+6O0Gl8lO571uI5onYdN1VIgOmwFbe+D8TcuzVjIZ/zvHrAGUcC\n" +
//                "AwEAAaNdMFswCwYDVR0PBAQDAgEGMAwGA1UdEwQFMAMBAf8wHQYDVR0OBBYEFF90\n" +
//                "tATATwda6uWx2yKjh0GynOEBMB8GA1UdIwQYMBaAFF90tATATwda6uWx2yKjh0Gy\n" +
//                "nOEBMA0GCSqGSIb3DQEBCwUAA4ICAQCVYaOtqOLIpsrEikE5lb+UARNSFJg6tpkf\n" +
//                "tJ2U8QF/DejemEHx5IClQu6ajxjtu0Aie4/3UnIXop8nH/Q57l+Wyt9T7N2WPiNq\n" +
//                "JSlYKYbJpPF8LXbuKYG3BTFTdOVFIeRe2NUyYh/xs6bXGr4WKTXb3qBmzR02FSy3\n" +
//                "IODQw5Q6zpXj8prYqFHYsOvGCEc1CwJaSaYwRhTkFedJUxiyhyB5GQwoFfExCVHW\n" +
//                "05ZFCAVYFldCJvUzfzrWubN6wX0DD2dwultgmldOn/W/n8at52mpPNvIdbZb2F41\n" +
//                "T0YZeoWnCJrYXjq/32oc1cmifIHqySnyMnavi75DxPCdZsCOpSAT4j4lAQRGsfgI\n" +
//                "kkLPGQieMfNNkMCKh7qjwdXAVtdqhf0RVtFILH3OyEodlk1HYXqX5iE5wlaKzDop\n" +
//                "PKwf2Q3BErq1xChYGGVS+dEvyXc/2nIBlt7uLWKp4XFjqekKbaGaLJdjYP5b2s7N\n" +
//                "1dM0MXQ/f8XoXKBkJNzEiM3hfsU6DOREgMc1DIsFKxfuMwX3EkVQM1If8ghb6x5Y\n" +
//                "jXayv+NLbidOSzk4vl5QwngO/JYFMkoc6i9LNwEaEtR9PhnrdubxmrtM+RjfBm02\n" +
//                "77q3dSWFESFQ4QxYWew4pHE0DpWbWy/iMIKQ6UZ5RLvB8GEcgt8ON7BBJeMc+Dyi\n" +
//                "kT9qhqn+lw==\n" +
//                "-----END CERTIFICATE-----\n" +
//                "\n" +
//                "-----BEGIN CERTIFICATE-----\n" +
//                "MIICiDCCAgygAwIBAgIIQX76UsB/30owDAYIKoZIzj0EAwMFADB6MQswCQYDVQQG\n" +
//                "EwJDTjEWMBQGA1UECgwNQW50IEZpbmFuY2lhbDEgMB4GA1UECwwXQ2VydGlmaWNh\n" +
//                "dGlvbiBBdXRob3JpdHkxMTAvBgNVBAMMKEFudCBGaW5hbmNpYWwgQ2VydGlmaWNh\n" +
//                "dGlvbiBBdXRob3JpdHkgRTEwHhcNMTkwNDI4MTYyMDQ0WhcNNDkwNDIwMTYyMDQ0\n" +
//                "WjB6MQswCQYDVQQGEwJDTjEWMBQGA1UECgwNQW50IEZpbmFuY2lhbDEgMB4GA1UE\n" +
//                "CwwXQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkxMTAvBgNVBAMMKEFudCBGaW5hbmNp\n" +
//                "YWwgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkgRTEwdjAQBgcqhkjOPQIBBgUrgQQA\n" +
//                "IgNiAASCCRa94QI0vR5Up9Yr9HEupz6hSoyjySYqo7v837KnmjveUIUNiuC9pWAU\n" +
//                "WP3jwLX3HkzeiNdeg22a0IZPoSUCpasufiLAnfXh6NInLiWBrjLJXDSGaY7vaokt\n" +
//                "rpZvAdmjXTBbMAsGA1UdDwQEAwIBBjAMBgNVHRMEBTADAQH/MB0GA1UdDgQWBBRZ\n" +
//                "4ZTgDpksHL2qcpkFkxD2zVd16TAfBgNVHSMEGDAWgBRZ4ZTgDpksHL2qcpkFkxD2\n" +
//                "zVd16TAMBggqhkjOPQQDAwUAA2gAMGUCMQD4IoqT2hTUn0jt7oXLdMJ8q4vLp6sg\n" +
//                "wHfPiOr9gxreb+e6Oidwd2LDnC4OUqCWiF8CMAzwKs4SnDJYcMLf2vpkbuVE4dTH\n" +
//                "Rglz+HGcTLWsFs4KxLsq7MuU+vJTBUeDJeDjdA==\n" +
//                "-----END CERTIFICATE-----\n" +
//                "\n" +
//                "-----BEGIN CERTIFICATE-----\n" +
//                "MIIDxTCCAq2gAwIBAgIUEMdk6dVgOEIS2cCP0Q43P90Ps5YwDQYJKoZIhvcNAQEF\n" +
//                "BQAwajELMAkGA1UEBhMCQ04xEzARBgNVBAoMCmlUcnVzQ2hpbmExHDAaBgNVBAsM\n" +
//                "E0NoaW5hIFRydXN0IE5ldHdvcmsxKDAmBgNVBAMMH2lUcnVzQ2hpbmEgQ2xhc3Mg\n" +
//                "MiBSb290IENBIC0gRzMwHhcNMTMwNDE4MDkzNjU2WhcNMzMwNDE4MDkzNjU2WjBq\n" +
//                "MQswCQYDVQQGEwJDTjETMBEGA1UECgwKaVRydXNDaGluYTEcMBoGA1UECwwTQ2hp\n" +
//                "bmEgVHJ1c3QgTmV0d29yazEoMCYGA1UEAwwfaVRydXNDaGluYSBDbGFzcyAyIFJv\n" +
//                "b3QgQ0EgLSBHMzCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAOPPShpV\n" +
//                "nJbMqqCw6Bz1kehnoPst9pkr0V9idOwU2oyS47/HjJXk9Rd5a9xfwkPO88trUpz5\n" +
//                "4GmmwspDXjVFu9L0eFaRuH3KMha1Ak01citbF7cQLJlS7XI+tpkTGHEY5pt3EsQg\n" +
//                "wykfZl/A1jrnSkspMS997r2Gim54cwz+mTMgDRhZsKK/lbOeBPpWtcFizjXYCqhw\n" +
//                "WktvQfZBYi6o4sHCshnOswi4yV1p+LuFcQ2ciYdWvULh1eZhLxHbGXyznYHi0dGN\n" +
//                "z+I9H8aXxqAQfHVhbdHNzi77hCxFjOy+hHrGsyzjrd2swVQ2iUWP8BfEQqGLqM1g\n" +
//                "KgWKYfcTGdbPB1MCAwEAAaNjMGEwHQYDVR0OBBYEFG/oAMxTVe7y0+408CTAK8hA\n" +
//                "uTyRMB8GA1UdIwQYMBaAFG/oAMxTVe7y0+408CTAK8hAuTyRMA8GA1UdEwEB/wQF\n" +
//                "MAMBAf8wDgYDVR0PAQH/BAQDAgEGMA0GCSqGSIb3DQEBBQUAA4IBAQBLnUTfW7hp\n" +
//                "emMbuUGCk7RBswzOT83bDM6824EkUnf+X0iKS95SUNGeeSWK2o/3ALJo5hi7GZr3\n" +
//                "U8eLaWAcYizfO99UXMRBPw5PRR+gXGEronGUugLpxsjuynoLQu8GQAeysSXKbN1I\n" +
//                "UugDo9u8igJORYA+5ms0s5sCUySqbQ2R5z/GoceyI9LdxIVa1RjVX8pYOj8JFwtn\n" +
//                "DJN3ftSFvNMYwRuILKuqUYSHc2GPYiHVflDh5nDymCMOQFcFG3WsEuB+EYQPFgIU\n" +
//                "1DHmdZcz7Llx8UOZXX2JupWCYzK1XhJb+r4hK5ncf/w8qGtYlmyJpxk3hr1TfUJX\n" +
//                "Yf4Zr0fJsGuv\n" +
//                "-----END CERTIFICATE-----");
//        try{
//
//            AlipayClient alipayClient = new DefaultAlipayClient(certAlipayRequest);
//            AlipayFundTransUniTransferRequest request = new AlipayFundTransUniTransferRequest();
//            request.setBizContent("{" +
//                    "\"out_biz_no\":\""+orderNo+"\"," + //商户端的唯一订单号，对于同一笔转账请求，商户需保证该订单号唯一。
//                    "\"trans_amount\":"+amount+"," + //订单总金额，单位为元，精确到小数点后两位
//                    "\"product_code\":\"TRANS_ACCOUNT_NO_PWD\"," +//单笔无密转账到支付宝账户固定为:TRANS_ACCOUNT_NO_PWD；单笔无密转账到银行卡固定为:TRANS_BANKCARD_NO_PWD;收发现金红包固定为:STD_RED_PACKET；
//                    "\"biz_scene\":\"DIRECT_TRANSFER\"," + //DIRECT_TRANSFER：单笔无密转账到支付宝/银行卡, B2C现金红包;PERSONAL_COLLECTION：C2C现金红包-领红包
//                    "\"order_title\":\"麒麟优车APP提现\"," + //转账业务的标题，用于在支付宝用户的账单里显示
//                    "\"original_order_id\":\"\"," + //原支付宝业务单号。C2C现金红包-红包领取时，传红包支付时返回的支付宝单号；B2C现金红包、单笔无密转账到支付宝/银行卡不需要该参数。
//                    "\"payee_info\":{" + //收款方信息
//                    "\"identity\":\""+ payeeIdentity +"\"," + //参与方的唯一标识
//                    "\"identity_type\":\"ALIPAY_USER_ID\"," +  // ALIPAY_USER_ID:支付宝的会员ID ALIPAY_LOGON_ID:支付宝登录号，支持邮箱和手机号格式
//                    "\"name\":\""+ payeeName +"\"" + //参与方真实姓名，如果非空，将校验收款支付宝账号姓名一致性。当identity_type=ALIPAY_LOGON_ID时，本字段必填。
//                    "    }," +
//                    "\"remark\":\"麒麟优车APP提现\"," + // 业务备注
//                    //"\"business_params\":\"{\\\"sub_biz_scene\\\":\\\"REDPACKET\\\"}\"" + //转账业务请求的扩展参数，支持传入的扩展参数如下：1、sub_biz_scene 子业务场景，红包业务必传，取值REDPACKET，C2C现金红包、B2C现金红包均需传入；2、withdraw_timeliness为转账到银行卡的预期到账时间，可选（不传入则默认为T1），取值T0表示预期T+0到账，取值T1表示预期T+1到账，因到账时效受银行机构处理影响，支付宝无法保证一定是T0或者T1到账；
//                    "  }");
//            AlipayFundTransUniTransferResponse response = alipayClient.certificateExecute(request);
//            if(response.isSuccess()){//调用成功
//                //查看成功内容
//                System.out.println("success--->" + response.getBody());
//            } else {//调用失败
//                System.out.println("fail--->" + response.getBody());
//                return null;
//            }
//        }catch (AlipayApiException e){
//            log.info("单笔转账异常--->" + e.getMessage());
//            return null;
//        }
//        return body.toString();
//    }


//    /**
//     * 查询转账订单结果
//     * @param out_biz_no 商户转账唯一订单号：发起转账来源方定义的转账单据ID。
//     *                   和支付宝转账单据号不能同时为空。当和支付宝转账单据号同时提供时，将用支付宝转账单据号进行查询，忽略本参数。
//     * @param order_id 支付宝转账单据号：和商户转账唯一订单号不能同时为空。
//     *                 当和商户转账唯一订单号同时提供时，将用本参数进行查询，忽略商户转账唯一订单号。
//     * @return
//     */
//    public static  String getQuerySingleTransferResult(String out_biz_no,String order_id) {
//        //构造client
//        CertAlipayRequest certAlipayRequest = new CertAlipayRequest();
//        //设置网关地址
//        certAlipayRequest.setServerUrl(PAY_DEFAULT_URL);
//        //设置应用Id
//        certAlipayRequest.setAppId(APPID);
//        //设置应用私钥
//        certAlipayRequest.setPrivateKey(RSA_PRIVATE);
//        //设置请求格式，固定值json
//        certAlipayRequest.setFormat("json");
//        //设置字符集
//        certAlipayRequest.setCharset("utf-8");
//        //设置签名类型
//        certAlipayRequest.setSignType("RSA2");
//        //设置应用公钥证书路径
//        certAlipayRequest.setCertPath("CRT/appCertPublicKey.crt");
//        //设置支付宝公钥证书路径
//        certAlipayRequest.setAlipayPublicCertPath("CRT/alipayCertPublicKey_RSA2.crt");
//        //设置支付宝根证书路径
//        certAlipayRequest.setRootCertPath("CRT/alipayRootCert.crt");
//        try{
//            AlipayClient alipayClient = new DefaultAlipayClient(certAlipayRequest);
//            AlipayFundTransOrderQueryRequest request = new AlipayFundTransOrderQueryRequest();
//            request.setBizContent("{" +
//                    "\"out_biz_no\":\""+out_biz_no+"\"," + //商户转账唯一订单号
//                    "\"order_id\":\""+order_id+"\"" + //支付宝转账单据号
//                    "  }");
//            AlipayFundTransOrderQueryResponse response = alipayClient.execute(request);
//            if(response.isSuccess()){
//                System.out.println("调用成功");
//            } else {
//                return null;
//            }
//        }catch (AlipayApiException alipayApiException){
//            log.info("" + alipayApiException.getMessage());
//        }
//        return null;
//    }
//    /**
//     * 转账业务单据查询接口
//     * @param orderNo 商家订单号
//     * @param alipayOrderNo 支付宝转账订单号
//     * @param alipayPayFundOrderId 支付宝支付资金流水号
//     * @return
//     */
//    public static String getQueryTransferResult(String orderNo,String alipayOrderNo,String alipayPayFundOrderId){
//
//        AlipayClient alipayClient = new DefaultAlipayClient(PAY_DEFAULT_URL, APPID,RSA_PRIVATE,"json",
//                "GBK",ALIPAY_PUBLIC_KEY,"RSA2");
//        AlipayFundTransCommonQueryRequest request = new AlipayFundTransCommonQueryRequest();
//        request.setBizContent("{" +
//                "\"product_code\":\"TRANS_ACCOUNT_NO_PWD\"," + //销售产品码，商家和支付宝签约的产品码，如果传递了out_biz_no则该字段为必传。可传值如下：STD_RED_PACKET：现金红包 TRANS_ACCOUNT_NO_PWD：单笔无密转账到支付宝账户 TRANS_BANKCARD_NO_PWD：单笔无密转账到银行卡
//                "\"biz_scene\":\"DIRECT_TRANSFER\"," + //描述特定的业务场景，如果传递了out_biz_no则该字段为必传。可取的业务场景如下：PERSONAL_PAY：C2C现金红包-发红包；PERSONAL_COLLECTION：C2C现金红包-领红包；REFUND：C2C现金红包-红包退回；DIRECT_TRANSFER：B2C现金红包、单笔无密转账
//                "\"out_biz_no\":\""+orderNo+"\"," + //商户转账唯一订单号，发起转账来源方定义的转账单据ID。
//                "\"order_id\":\""+alipayOrderNo+"\"," + //支付宝转账单据号。
//                "\"pay_fund_order_id\":\""+alipayPayFundOrderId+"\"" + //支付宝支付资金流水号。
//                "  }");
//        try{
//            AlipayFundTransCommonQueryResponse response = alipayClient.execute(request);
//            if(response.isSuccess()){//调用成功
//
//            } else {//调用失败
//                return null;
//            }
//        }catch (AlipayApiException e){
//            log.info("转账业务单据查询异常--->" + e.getMessage());
//        }
//        return null;
//    }
//
//    /**
//     * 支付宝资金账户资产查询接口
//     * @return
//     * @throws AlipayApiException
//     */
//    public static String getAlipayFundAccountQuery(String alipayUserId) {
//        AlipayClient alipayClient = new DefaultAlipayClient(PAY_DEFAULT_URL, APPID,RSA_PRIVATE,"json",
//                "GBK",ALIPAY_PUBLIC_KEY,"RSA2");
//        AlipayFundAccountQueryRequest request = new AlipayFundAccountQueryRequest();
//        request.setBizContent("{" +
//                "\"alipay_user_id\":\""+alipayUserId+"\"," + //支付宝会员 id。
//                "\"merchant_user_id\":\"\"," + //商户会员的唯一标识。如果传入的user_id为虚拟账户userId，此字段必传并比对一致性。
//                "\"account_product_code\":\"\"," + //说明：开户产品码。如果查询托管子户余额，必传且必须传入与开户时传入的值一致。
//                "\"account_type\":\"ACCTRANS_ACCOUNT\"," + //查询的账号类型，查询余额账户值为ACCTRANS_ACCOUNT。必填。
//                "\"account_scene_code\":\"\"," + //说明：开户场景码，与开户产品码不可同时传递。
//                "\"ext_info\":\"{\\\"agreement_no\\\":\\\"\\\"}\"" +
//                "  }");
//        try{
//            AlipayFundAccountQueryResponse response = alipayClient.execute(request);
//            if(response.isSuccess()){//调用成功
//
//            } else {//调用失败
//                return null;
//            }
//        }catch (AlipayApiException e){
//            log.info("支付宝资金账户资产查询异常--->" + e.getMessage());
//        }
//        return null;
//    }
//
//    /** java 支付宝公钥证书如何解析成支付宝公钥 */
//    public static void getAlipayPublicKey(){
//        try{
//            //输入支付宝公钥证书绝对路径
//            String alipayPublicCertPath = "C:\\Users\\Administrator\\Desktop\\appCertPublicKey.crt";
//            String alipayPublicKey = AlipaySignature.getAlipayPublicKey(alipayPublicCertPath);
//            //输出支付宝公钥的值
//            System.out.println("alipayPublicKey:"+alipayPublicKey);
//        }catch (AlipayApiException alipayApiException){
//            System.out.println("err -->" + alipayApiException.getMessage());
//        }
//    }
//
//    /**
//     * 单笔转账 具体实现的方法（普通方式）--新版本
//     * @param orderNo 商家订单号
//     * @param amount    金额
//     * @param payeeIdentity 参与方的唯一标识
//     * @param payeeName   参与方真实姓名
//     * @return
//     */
//    public static void getSingleTransfer2(String orderNo, BigDecimal amount,String payeeIdentity,String payeeName){
//        AlipayClient alipayClient = new DefaultAlipayClient(PAY_DEFAULT_URL, APPID,RSA_PRIVATE,"json",
//                "GBK",ALIPAY_PUBLIC_KEY,"RSA2");
//        AlipayFundTransUniTransferRequest request = new AlipayFundTransUniTransferRequest();
//        request.setBizContent("{" +
//                "\"out_biz_no\":\""+orderNo+"\"," +
//                "\"trans_amount\":"+amount+"," +
//                "\"product_code\":\"TRANS_ACCOUNT_NO_PWD\"," +
//                "\"biz_scene\":\"DIRECT_TRANSFER\"," +
//                "\"order_title\":\"麒麟优车APP提现\"," +
//                "\"payer_info\":{" +
//                "\"identity\":\"562463350@qq.com\"," +
//                "\"identity_type\":\"ALIPAY_LOGON_ID\"," +
//                "\"name\":\"成都融智汽车服务有限公司\"," +
//                "    }," +
//                "\"payee_info\":{" +
//                "\"identity\":\""+payeeIdentity+"\"," +
//                "\"identity_type\":\"ALIPAY_USER_ID\"," +
//                "\"name\":\""+payeeName+"\"," +
//                "    }," +
//                "\"remark\":\"麒麟优车APP提现\"," +
//                //"\"business_params\":\"{\\\"sub_biz_scene\\\":\\\"REDPACKET\\\"}\"" +
//                "  }");
//        try{
//            AlipayFundTransUniTransferResponse response = alipayClient.execute(request);
//            if(response.isSuccess()){
//                System.out.println("调用成功" + response.getBody());
//            } else {
//                System.out.println("调用失败" + response.getBody());
//            }
//        }catch (AlipayApiException alipayApiException){
//            System.out.println("单笔转账err -->" + alipayApiException.getMessage());
//        }
//    }

    /**
     * 单笔转账 具体实现的方法（普通方式）--老版本
     * @param orderNo 商家订单号
     * @param amount    金额
     * @param payeeIdentity 参与方的唯一标识
     * @param payeeName   参与方真实姓名
     * @return
     */
    public static String getSingleTransfer3(String orderNo, BigDecimal amount,String payeeIdentity,String payeeName){
        //调用后返回信息体
        StringBuffer body = new StringBuffer();

        AlipayClient alipayClient = new DefaultAlipayClient(PAY_DEFAULT_URL, APPID,RSA_PRIVATE,"json",
                "GBK",ALIPAY_PUBLIC_KEY,"RSA2");
        AlipayFundTransToaccountTransferRequest request = new AlipayFundTransToaccountTransferRequest();
        request.setBizContent("{" +
                "\"out_biz_no\":\""+orderNo+"\"," +
                "\"payee_type\":\"ALIPAY_USERID\"," +
                "\"payee_account\":\""+payeeIdentity+"\"," +
                "\"amount\":\""+amount+"\"," +
//                "\"payer_show_name\":\"上海交通卡退款\"," +
//                "\"payee_real_name\":\"张三\"," +
//                "\"remark\":\"转账备注\"" +
                "  }");
        try{
            AlipayFundTransToaccountTransferResponse response = alipayClient.execute(request);
            if(response.isSuccess()){
                //支付宝支付资金流水号，账务单号
                String orderId = response.getOrderId();
                //订单支付时间
                String payDate = response.getPayDate();
                //支付的结果
                String msg = response.getMsg();
                body.append(msg);
                body.append(",");
                body.append(orderId);
                body.append(",");
                body.append(payDate);
            } else {
                log.info("单笔转账调用失败:" + response.getBody());
                return null;
            }
        }catch (AlipayApiException alipayApiException){
            log.info("单笔转账err -->" + alipayApiException.getMessage());
            return null;
        }
        return body.toString();
    }

    //开发者测试使用  正式转账请勿！！！！
//    public static void main(String[] args){
//        String orderNo = String.valueOf(IDUtil.nextId());
//        BigDecimal amount = new BigDecimal("0.1");
//        String payeeIdentity = "2088912685324666";
//        getSingleTransfer3(orderNo,amount,payeeIdentity,null);
//
//        //支付宝公钥证书如何解析成支付宝公钥
//        //getAlipayPublicKey();
//    }
}
